/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import ClasesAModificar.PersonajeMoficar;
import javax.swing.JOptionPane;
import src.Core;

/**
 *
 * @author Strauzen
 */
public class VentanaConsultaPersonaje extends javax.swing.JFrame {

    Ventana1 v1;
    
    /**
     * Creates new form VentanaConsultaPersonaje
     */
    public VentanaConsultaPersonaje(Ventana1 v1) {
        this.v1 = v1;
        initComponents();
    }
    
    private boolean correcto(){
        try{
            if(!this.jTextField_vpFechaNaci.getText().equals(""))
                Integer.parseInt(this.jTextField_vpFechaNaci.getText());
            if(!this.jTextField_vpFechaDefun.getText().equals(""))
                Integer.parseInt(this.jTextField_vpFechaDefun.getText());
            
            if(!this.jTextField_vpFechaNaci.getText().equals("") && this.jTextField_vpFechaNaci.getText().length() != 8)
                throw new Exception();            
            if(!this.jTextField_vpFechaDefun.getText().equals("") && this.jTextField_vpFechaDefun.getText().length() != 8)
                throw new Exception();
                
            return true;
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor rellene las fechas de la siguiente manera:\n"
                    + "ej. 20120101 siendo los 4 primeros numeros el año, los dos siguientes el mes\n"
                    + "y los dos ultimos el día\n\n");
            return false;
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vpNombApe = new javax.swing.JLabel();
        jTextField_vpNombApe = new javax.swing.JTextField();
        jLabel_vpFechaNaci = new javax.swing.JLabel();
        jTextField_vpFechaNaci = new javax.swing.JTextField();
        jLabel_vpLugarNaci = new javax.swing.JLabel();
        jTextField_vpLugarNaci = new javax.swing.JTextField();
        jLabel_vpFechaDefun = new javax.swing.JLabel();
        jTextField_vpFechaDefun = new javax.swing.JTextField();
        jLabel_vpLugarDefun = new javax.swing.JLabel();
        jTextField_vpLugarDefun = new javax.swing.JTextField();
        jLabel_vpBiografia = new javax.swing.JLabel();
        jTextField_vpBiografia = new javax.swing.JTextField();
        jButton_VMPTerminar = new javax.swing.JButton();
        jLabel_vcpAlias = new javax.swing.JLabel();
        jTextField_vcpAlias = new javax.swing.JTextField();
        jLabel_vcpCargo = new javax.swing.JLabel();
        jTextField_vcpCargo = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel_vpNombApe.setText("Nombre y Apellidos");

        jLabel_vpFechaNaci.setText("Fecha de Nacimiento");

        jLabel_vpLugarNaci.setText("Lugar de Nacimiento");

        jLabel_vpFechaDefun.setText("Fecha de Defuncion");

        jLabel_vpLugarDefun.setText("Lugar de Defuncion");

        jLabel_vpBiografia.setText("Biografia");

        jButton_VMPTerminar.setText("Terminar");
        jButton_VMPTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton_VMPTerminarMousePressed(evt);
            }
        });

        jLabel_vcpAlias.setText("Alias");

        jLabel_vcpCargo.setText("Cargo");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpNombApe)
                    .addComponent(jLabel_vpFechaNaci)
                    .addComponent(jLabel_vpLugarNaci)
                    .addComponent(jLabel_vpFechaDefun)
                    .addComponent(jLabel_vpLugarDefun))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_vpFechaDefun, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .addComponent(jTextField_vpLugarNaci, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .addComponent(jTextField_vpFechaNaci, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .addComponent(jTextField_vpNombApe, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .addComponent(jTextField_vpLugarDefun, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vpBiografia)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vpBiografia, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(152, 152, 152)
                .addComponent(jButton_VMPTerminar)
                .addContainerGap(153, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcpAlias)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcpAlias, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcpCargo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcpCargo, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpNombApe)
                    .addComponent(jTextField_vpNombApe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpFechaNaci)
                    .addComponent(jTextField_vpFechaNaci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpLugarNaci)
                    .addComponent(jTextField_vpLugarNaci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpFechaDefun)
                    .addComponent(jTextField_vpFechaDefun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpLugarDefun)
                    .addComponent(jTextField_vpLugarDefun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vpBiografia)
                    .addComponent(jTextField_vpBiografia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vcpAlias)
                    .addComponent(jTextField_vcpAlias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vcpCargo)
                    .addComponent(jTextField_vcpCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton_VMPTerminar))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_VMPTerminarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMPTerminarMousePressed
        // TODO add your handling code here:
        if(correcto())
        {
            int fechaNac = -1;
            int fechaDef = -1;
            if(!this.jTextField_vpFechaNaci.getText().equals("")) {
                fechaNac = Integer.parseInt(this.jTextField_vpFechaNaci.getText());
            }
            if(!this.jTextField_vpFechaDefun.getText().equals("")) {
                fechaDef = Integer.parseInt(this.jTextField_vpFechaDefun.getText());
            }
            
            PersonajeMoficar PM = new PersonajeMoficar(this.jTextField_vpNombApe.getText(), 
                    fechaNac , this.jTextField_vpLugarNaci.getText(), fechaDef, 
                    this.jTextField_vpLugarDefun.getText(), this.jTextField_vpBiografia.getText(), "", "", "", -1);
            String perso =  Core.buscaEnLaBDPorPersonaje(PM);
            VentanaConsultaEleccion vce = new VentanaConsultaEleccion(v1);
            vce.modificarTexto(perso);
            vce.setVisibleVCETipo(false);
            vce.setPadre(1);
            vce.setVisible(true);
            this.setVisible(false);
            this.dispose();
        }
    }//GEN-LAST:event_jButton_VMPTerminarMousePressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_VMPTerminar;
    private javax.swing.JLabel jLabel_vcpAlias;
    private javax.swing.JLabel jLabel_vcpCargo;
    private javax.swing.JLabel jLabel_vpBiografia;
    private javax.swing.JLabel jLabel_vpFechaDefun;
    private javax.swing.JLabel jLabel_vpFechaNaci;
    private javax.swing.JLabel jLabel_vpLugarDefun;
    private javax.swing.JLabel jLabel_vpLugarNaci;
    private javax.swing.JLabel jLabel_vpNombApe;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vcpAlias;
    private javax.swing.JTextField jTextField_vcpCargo;
    private javax.swing.JTextField jTextField_vpBiografia;
    private javax.swing.JTextField jTextField_vpFechaDefun;
    private javax.swing.JTextField jTextField_vpFechaNaci;
    private javax.swing.JTextField jTextField_vpLugarDefun;
    private javax.swing.JTextField jTextField_vpLugarNaci;
    private javax.swing.JTextField jTextField_vpNombApe;
    // End of variables declaration//GEN-END:variables
}
